<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<head>

    <script type="text/javascript" src="<%=jsPath%>/platform/platform_jt809StatusView.js?v=8503021"></script><!--功能插件-->
<script>
      
    
///////////////////////////////////////////////////////立即运行方法

//初始化控件,页面加载时即加载，不需要调用
$(function(){
    //初始化表格
    $("#pl_809s_grid_Grid").datagrid({
        height:"100%",
        toolbar:"#pl_809s_grid_tool",//工具条
        pagination:true,//分页工具栏
		pageList:[15,30,50,100],
		pageSize:15,
		singleSelect:true,//单选
		rownumbers:true,//行号
		striped:true,//隔行变色
		fitColumns: true,//填充列
		checkOnSelect: false,//选中则勾选
		selectOnCheck: false,//勾选则选中
    });

});


var pl_809s_grid = {};
pl_809s_grid.slctUrl = globalConfig.webPath + '/basicSlctAction/basicSelectData.action';
pl_809s_grid.slctPagiUrl = globalConfig.webPath + '/basicSlctAction/basicSelectPaginationData.action';
pl_809s_grid.transUrl = globalConfig.webPath + '/platformFun/viewJt809TransPage.action';
pl_809s_grid.transPageTitle = '定位数据转发';
pl_809s_grid.endTimeOffset = 30;//起止时间截止日期偏移量，向后延迟多少秒

////////////////////////////////////////////////////////初始化控件    
//接口，初始化所有控件
pl_809s_grid.initDivs = function(){
    pl_jt809View.init();//进行初始化
    pl_jt809View.initNameDiv('pl_809s_grid_name');
    pl_jt809View.initTypeDiv('pl_809s_grid_type');
    pl_jt809View.initStatusDiv('pl_809s_grid_Status');
    let today = Utility.today();
    $("#pl_809s_grid_startTime").datebox('setValue',today);
    $("#pl_809s_grid_endTime").datebox('setValue',today);
    this.initBtnFun();

}

//初始化按钮事件
pl_809s_grid.initBtnFun = function(){
    //查询明细
    $("#pl_809s_grid_BtnQuery").click(function(e){
        pl_jt809View.setFirstPage('pl_809s_grid_Grid');
        pl_809s_grid.slctAllData(1);
    });

    //查询统计数据
    $("#pl_809s_grid_BtnCount").click(function(e){
        pl_jt809View.setFirstPage('pl_809s_grid_Grid');
        pl_809s_grid.slctCountData(1);
    });
    $("#pl_809s_grid_Grid").datagrid("getPager").pagination({
		onSelectPage:function(pageNumber,pageSize){
			pl_809s_grid.slctAllData(pageNumber,pageSize);	
		}
	});
}

//////////////////////////////////////////////////////查询所有数据
//查询明细页面
pl_809s_grid.slctAllData = function(pageNumber,pageSize){
    let that = this;
    let param = this.getSlctParam(pageNumber,pageSize);
    // pl_jt809View.outDebug("查询明细数据所需参数为：" , param);
    Utility.getAjaxData(pl_809s_grid.slctPagiUrl, JSON.stringify(param), function (data) {
        // pl_jt809View.outDebug("接收到809状态数据：", data);
        if (data.success) {
            that.formatDetailData(data.data.rows);
            // pl_jt809View.outDebug("传回的数据为：" ,data.data);
            $("#pl_809s_grid_Grid").datagrid('loadData', data.data);

        } else {
            DataUtil.outError("查询809状态数据失败：" + data.message);
        }
    });
}


//获取查询参数
pl_809s_grid.getSlctParam = function(pageNumber,pageSize){
    let param = DataUtil.getParamFromForm("pl_809s_grid_form");
    param.start += ' 00:00:00';
    let end = new Date(new Date(param.end + ' 23:59:59').getTime() + this.endTimeOffset * 1000);
    param.end = Utility.dateToString(end);
    if(isNaN(pageNumber)){
        param.pageNumber =  $("#pl_809s_grid_Grid").datagrid("getPager").data("pagination").options.pageNumber;
    }else{
        param.pageNumber = pageNumber;
    }

    if(isNaN(pageSize)){
        param.pageSize = $("#pl_809s_grid_Grid").datagrid("getPager").data("pagination").options.pageSize;
    }else{
        param.pageSize = pageSize;
    }
    return param;
}

//解析明细信息
pl_809s_grid.formatDetailData = function(data){
    if(data && data.length > 0){
        for(let i=0 ; i<data.length ; i++){
            let item = data[i];
            if(item.type == 'mainLink' && item.status == '0'){
                let paramStr = '?name=' +item.name + '&startTime=' + item.startTime + '&endTime=' + item.endTime;
                let url = this.transUrl + paramStr;
                data[i].remark = '<a href="#" onclick="javascript:pl_809s_grid.addTabToMainTabs(&quot;' + url + '&quot;,&quot;' //
                    + this.transPageTitle + '&quot;);">补数据</a>';

            }
        }
    }
}


//查询统计数据
pl_809s_grid.slctCountData = function(pageNumber){
    let param = this.getSlctParam(pageNumber);
    param.queryId = 'jt809Command.getTimeSpanStatusCountData';
    // pl_jt809View.outDebug("查询统计数据所需参数为：" , param);
    Utility.getAjaxData(pl_809s_grid.slctUrl, JSON.stringify(param), function (data) {
        // pl_jt809View.outDebug("接收到809状态统计数据：", data);
        if (data.success) {
            $("#pl_809s_grid_Grid").datagrid('loadData', data.data);

        } else {
            DataUtil.outError("查询809状态统计数据失败：" + data.message);
        }
    });
}


//////////////////////////////////////////////////////功能
/*
在主框架中添加一个选项卡
*/
pl_809s_grid.addTabToMainTabs = function(url,title){
	try {
		//动态页面添加
        var content = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;display:block;"></iframe>';
        var mainTab = parent.$("#mainTab");
        if(mainTab){
            if(mainTab.tabs('exists', title)){
				mainTab.tabs('close', title);
            }
			mainTab.tabs("add", {
				title: title,
				closable: true,
				// id: 1,
				content: content//动态页面
			});
            
        }
    } catch (error) {
        console.error("809状态监控页面中添加选项卡错误："+error);
    }
}


///////////////////////////////////////////////////////格式化数据

//格式化链路名称
pl_809s_grid.formatLinkName = function(value,rowData,rowIndex){
    return pl_jt809View.getLinkValueStr(value,'name');
}

//格式化链路类型
pl_809s_grid.formatLinkType = function(value,rowData,rowIndex){
    return pl_jt809View.getLinkValueStr(value,'type');
}

//格式化链路状态
pl_809s_grid.formatLinkStatus = function(value,rowData,rowIndex){
    return pl_jt809View.getLinkValueStr(value,'status');
}

//格式化链路时长
pl_809s_grid.formatLinkLength = function(value,rowData,rowIndex){
    return pl_jt809View.getTimeLengthStr(value);
}

///////////////////////////////////////////////////////加载后执行
$(document).ready(function(){
    pl_809s_grid.initDivs();
});




</script>





</head>
<body style="background-color:rgb(251,251,251);height:98%;width:99%;" class="base_ver_flexStartDiv_css">
    <div id="pl_809s_grid_tool" style="width:100%;" class="sh_css_basFontSize">
        <form id="pl_809s_grid_form" action="<%=ApplicationPath%>/export.action" >
            <input type="hidden" name="queryId" value="jt809Command.getTimeSpanStatusData" />            
            <!--上层按钮栏-->
            <div style="width:80%;margin-left: 15px;margin-top:5px;">
                <a id="pl_809s_grid_BtnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">导出</a>
                &nbsp;&nbsp;
                <a id="pl_809s_grid_BtnReset" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'">重置</a>
            </div>
            <!--下层查询工具栏-->
            <hr>
            <div style="width:100%;height:30px;" class="base_hori_flexStartDiv_css">
                <!--左侧条件样式-->
                <div style="height:100%;margin-top:7px;margin-left:15px;" class="base_ver_Around_leftDiv_css">
                    <div>
                        链路名称：
                        <select id="pl_809s_grid_name" name="name" style="width:100px;"></select>
                        &nbsp;&nbsp;
                        链路类型：
                        <select id="pl_809s_grid_type" name="type" style="width:100px;"></select>
                        &nbsp;&nbsp;
                        链路状态：
                        <select id="pl_809s_grid_Status" name="status" style="width:100px;"></select>
                        &nbsp;&nbsp;
                        起止时间
                        <input type="text" name="start" id="pl_809s_grid_startTime" class="easyui-datebox" style="width:100px;" />
                        <span>-</span>
                        <input type="text" name="end" id="pl_809s_grid_endTime" class="easyui-datebox" style="width:100px;" />
                    </div>
                </div>
                <!--右侧按钮-->
                <div style="margin-left:20px;" class="base_hori_flexCenterDiv_css">
                    <!-- <a id="allAlarmAtnQuery" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> -->
                    <div id="pl_809s_grid_BtnQuery" class="sh_css_btn">
                        <div class="ui-icon icon-search" style="width:16px;height:16px;"></div>
                        <span>查询明细</span>
                    </div>
                    &nbsp;
                    <div id="pl_809s_grid_BtnCount" class="sh_css_btn">
                        <div class="ui-icon icon-search" style="width:16px;height:16px;"></div>
                        <span>查询统计数据</span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <table id="pl_809s_grid_Grid" class="easyui-datagrid" style="width:100%;">
        <thead>
            <tr>
                <th data-options="field:'name',formatter:pl_809s_grid.formatLinkName" width="70">链路名称</th>
                <th data-options="field:'type',formatter:pl_809s_grid.formatLinkType" width="70">链路类型</th>
                <th data-options="field:'status',formatter:pl_809s_grid.formatLinkStatus" width="60">链路状态</th>
                <th data-options="field:'startTime'" width="120">开始时间</th>
                <th data-options="field:'endTime'" width="120">结束时间</th>
                <th data-options="field:'length',formatter:pl_809s_grid.formatLinkLength" width="120">时长(秒)</th>
                <th data-options="field:'remark'" width="100">备注</th>
            </tr>
        </thead>
    </table>
</body>